package com.cl.ks.flow.factory;

import com.cl.ks.flow.handler.SparkNodeHandler;
import com.cl.ks.flow.base.BaseFlowNodeHandler;
import com.cl.ks.flow.enums.NodeHandlerEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class KsFlowGraphNodeFactory  implements InitializingBean {
    @Autowired
    private List<BaseFlowNodeHandler> sparkNodeHandlerList;
    @Autowired
    private SparkNodeHandler sparkNodeHandler;

    private static final Map<NodeHandlerEnum, BaseFlowNodeHandler> nodeHandlerRouters = new ConcurrentHashMap<>();


    public BaseFlowNodeHandler getKsFlowGraphNodeHandler(String flowNodeName) {
        return nodeHandlerRouters.get(NodeHandlerEnum.getNodeHandlerByNodeName(flowNodeName));
    }

    @Override
    public void afterPropertiesSet() {
        for (BaseFlowNodeHandler service : sparkNodeHandlerList){
            nodeHandlerRouters.put(service.getType(), service);
        }
    }
}